﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Aliyeye.Car.Net.UI.Components;
using Aliyeye.Car.Net.UI.PopupDialog;
using Aliyeye.Car.Net.UI.Common;

namespace Aliyeye.Car.Net.UI.OrderModel
{
    public partial class IllegalList : BaseForm
    {
        public Aliyeye.Car.Net.UI.IllegalSvc.SoapHeaderClass sopaHeaderIllegal = new Aliyeye.Car.Net.UI.IllegalSvc.SoapHeaderClass();
        int reserveId = 0;
        public IllegalList()
        {
            InitializeComponent();
        }

        public IllegalList(int id)
        {
            InitializeComponent();
            reserveId = id;
        }

        private int dgvBind()
        {
            string _strSql = "Reserve.BookTime<=Illegal.Time and Illegal.Time<=Reserve.EndBooktime and Reserve.id='" + reserveId.ToString() + "'";
            PageData pageData = new PageData(this, pager1, this.overlay);
            pageData.TableName = "Illegal left join Car on Illegal.CarCode=Car.Code left join Reserve on Car.Id=Reserve.CarId";
            pageData.PrimaryKey = "Illegal.Id";
            pageData.OrderStr = "Illegal.Id desc";
            pageData.PageIndex = this.pager1.PageCurrent;
            pageData.PageSize = this.pager1.PageSize;
            pageData.QueryCondition = _strSql;
            pageData.QueryFieldName = "Illegal.*";

            dgvInfo.AutoGenerateColumns = false;
            DataSet ds = pageData.QueryDataTable();
            dgvInfo.DataSource = this.pager1.bindingSource;
            return pageData.TotalCount;
        }

        private void Illegal_Load(object sender, EventArgs e)
        {
            this.pager1.PageCurrent = 1;
            this.pager1.Bind();
        }


        private int pager1_EventPaging(EventPagingArg e)
        {
            return dgvBind();
        }


        private void dgvInfo_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            if (this.dgvInfo.Rows.Count != 0)
            {
                for (int i = 0; i < this.dgvInfo.Rows.Count; )
                {
                    this.dgvInfo.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.PapayaWhip;
                    i += 2;
                }
            }
        }

        private void dgvInfo_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (this.dgvInfo.Columns[e.ColumnIndex].Name == "状态")
            {
                if (e.Value.ToString() == "已结算")
                {
                    e.CellStyle.ForeColor = Color.Blue;
                }
                else
                {
                    e.CellStyle.ForeColor = Color.Red;
                }
            }
        }
    }
}
